<?php
namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	//系统首页
    public function index(){

        $category = D('Category')->getTree();
        $lists    = D('Document')->lists(null);
        $this->assign('category',$category);//栏目
        $this->assign('lists',$lists);//列表
        $this->assign('page',D('Document')->page);//分页
        //查询分类菜单
        $this->assign('__MENUTOP__', $this->getMenusTop());
        $this->assign('__MENU__', $this->getMenusAll());
        $this->assign('_pictures', $this->getTurnPictures('首页展示'));
        $this->display();
    }
    
    public function faq(){
    	$lists    =M('Faqs')->select();
    	for ($i=0; $i<count($lists); $i++)
    	{
    		$lists[$i]['rownum']=$i+1;
    	}
    	$this->assign('_list',$lists); 
    	$this->display();
    }
    
    //查询所有图片
	public function getPicture()
	{
		$map['type']='首页展示';
		$row=M('PictureTurn')->where($map)->select();
		for ($i=0; $i<count($row); $i++)
		{
			$responce->rows[$i]=array(
					"path"=>$row[$i]['path'],
					"name"=>$row[$i]['name'],
					"id"=>$row[$i]['id'] 
			);
		}
		
		$row1=M('Phoneindexicon')->select();
		for ($i=0; $i<count($row1); $i++)
		{
			$responce->rowsa[$i]=array(
				"path"=>$row1[$i]['path'],
				"name"=>$row1[$i]['name'],
				"id"=>$row1[$i]['id']
			);
		}
		$this->ajaxReturn(json_encode($responce));
	}
	public function getShop($category=null)
	{
		$map['categoryno']  = $category;	
		$row=M('Phoneshop')->where($map)->select();
		for ($i=0; $i<count($row); $i++)
		{
				$responce->rows[$i]=array(
						"path"=>$row[$i]['path'],
						"productname"=>$row[$i]['productname'],
						"brandname"=>$row[$i]['brandname'],
						"stock"=>$row[$i]['stock'],
						"review"=>$row[$i]['review'],
						"price"=>$row[$i]['price'],
						"introduce"=>$row[$i]['introduce'],
						"status"=>$row[$i]['status'],
						"category"=>$row[$i]['category'],
						"categoryno"=>$row[$i]['categoryno']
						
				);
		}
		$this->ajaxReturn(json_encode($responce));
	}
	public function getDonate()
	{
		$row=M('Phonepublicwelfare')->select();
		for ($i=0; $i<count($row); $i++)
		{
			$responce->rows[$i]=array(
					"path"=>$row[$i]['path'],
					"contributename"=>$row[$i]['contributename'],
					"donor"=>$row[$i]['donor'],
					"nickname"=>$row[$i]['nickname'],
					"donationobject"=>$row[$i]['donationobject'],
					"member"=>$row[$i]['member'],
					"published"=>$row[$i]['published'],
					"status"=>$row[$i]['status'],
					"receivedate"=>$row[$i]['receivedate'] 
			);
		}
		$this->ajaxReturn(json_encode($responce));
	}
	public function save($message=null,$phone=null,$landline=null,$callbactime=null,$appointtime=null,$type=null) {
		$Phoneappointment= D('Phoneappointment'); 
		if(!empty($message))$formdata['message']=$message;
		if(!empty($phone))$formdata['phone']=$phone;
		if(!empty($landline))$formdata['landline']=$landline;
		if(!empty($callbactime))$formdata['callbactime']=$callbactime;
		if(!empty($appointtime))$formdata['appointtime']=$appointtime;
		if(!empty($type))$formdata['type']=$type;
		
		if(!$Phoneappointment->add($formdata))
		{
			$responce->status=false;
			$responce->result = '插入成功';
			
		}
		else
		{
			$responce->status=false;
			$responce->result = '插入出错';
		}
		$this->ajaxReturn(json_encode($responce));
	}
}